package eg.backend.query;

import java.util.Date;

import eg.backend.util.Constants;

public class DateRange {
	private Date from;
	private Date to;
	private String name;
	private DateId dateId;

	public DateRange(Date from, Date to, String name, DateId dateId) {
		this.from = from;
		this.to = to;
		this.name = name;
		this.dateId = dateId;
	}

	public Date getFrom() {
		return from;
	}

	public void setFrom(Date from) {
		this.from = from;
	}

	public Date getTo() {
		return to;
	}

	public void setTo(Date to) {
		this.to = to;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDateId() {
		return Constants.TIME_DIMENSION_PREFIX + dateId.toString();
	}

	public void setDateId(DateId dateId) {
		this.dateId = dateId;
	}

	public static class DateId {
		private int year = -1;
		private int month = -1;
		private int week = -1;
		private int day = -1;
		
		public DateId(int year){
			this.year = year;
		}
		public DateId(int year, int month){
			this.year = year;
			this.month = month;
		}
		public DateId(int year, int month, int week){
			this.year = year;
			this.month = month;
			this.week = week;
		}
		public DateId(int year, int month, int week, int day){
			this.year = year;
			this.month = month;
			this.week = week;
			this.day = day;
		}
		
		@Override
		public String toString() {
			String result = "";
			if(year > 0) {
				result += year;
				if(month > 0) {
					result += "-" + Constants.INTEGER_FORMAT.format(month);
					if(week > 0) {
						result += "-" + Constants.INTEGER_FORMAT.format(week);
						if(day > 0) {
							result += "-" + Constants.INTEGER_FORMAT.format(day);
						}
					}
				}
			}
			
			return result;
		}
	}
	
}
